package com.ruoyi.carUser.controller;

import com.ruoyi.carUser.service.OrderService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.OrderDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderCarController {
    @Autowired
    private OrderService orderService;
    @RequestMapping("getOrderInfo")
    public R orderExit(OrderDetails orderDetails){
        OrderDetails orderDetails1 = orderService.selectOrderDetails(orderDetails);
        if (orderDetails1 != null){
            return R.fail("你有未支付订单，请先在我的订单页面进行支付");
        }
        orderDetails.setPaytus("待支付");
        int i = orderService.insertOrder(orderDetails);
        if (i==0){
            return R.fail("订单创建失败");
        }
        OrderDetails orderDetails2 = orderService.selectOrderDetails(orderDetails);
        Long orderId = orderDetails2.getOrderDetailsId();
        return R.ok(orderId);
    }
    @RequestMapping("updateCodeAndImg")
    public R updateCodeAndImg(OrderDetails orderDetails){
        int i = orderService.updateCodeAndImg(orderDetails);
        if (i==0){
            return R.fail("失败啦");
        }
        return R.ok("订单二维码和核销码更新成功");
    }

}
